const express=require('express');
const app=express();
app.get('/server',(request,response)=>{
    //防止跨域错误
    response.setHeader('Access-Control-Allow-Origin','*');
    response.send('hello');
})
app.post('/server',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*');
    response.send('hello');
})
app.get('/json-server',function(request,response){
    response.setHeader('Access-Control-Allow-Origin','*');
    var data={
        name:'andy',
        age:18
    }
    //转成json类型
    var str=JSON.stringify(data);
    response.send(str);
})
app.get('/jsonp-server',function(request,response){
        var data={
            exist:1,
            msg:'用户已存在'
        }
        var str=JSON.stringify(data);
        response.end(`handle(${str})`);
})
app.listen(5050,()=>{
    console.log('5050');
})